package com.taplinker.client.crm.rpc;

import com.google.protobuf.InvalidProtocolBufferException;
import com.taplinker.client.AppConfigContext;
import com.taplinker.client.crm.domain.CustomerInfo;
import com.taplinker.core.rpc.Result;
import com.taplinker.core.rpc.command.SimpleBaseCommand;
import com.taplinker.core.rpc.http.HttpTemplate;
import com.taplinker.core.rpc.http.protocol.HttpMethod;
import com.taplinker.dto.web.ActionProto.Action;
/**
 * 删除客户
 * @author djbian
 *
 */
public class DeleteCustomer  extends SimpleBaseCommand {

	private CustomerInfo info;
	public DeleteCustomer(CustomerInfo info) {
		this.info = info;
	}
	
	@Override
	public Result go() {
		return new HttpTemplate().exchange(AppConfigContext.TAPLINKER_WEB
				+ "/services/crm/v1/delete/"+info.getCustomer().getId()
				, HttpMethod.DELETE);
	}
	
	@Override
	public void yes(Result result) {
		super.yes(result);
		try {
			Action action = Action.parseFrom((byte[])result.object);
			info.addClientAction(action.getCsActionList());
		} catch (InvalidProtocolBufferException e) {
			e.printStackTrace();
		}
	}

}